<?php

class DownloadController extends Controller
{
	/**
	 * @var string the default layout for the views. Defaults to '//layouts/column2', meaning
	 * using two-column layout. See 'protected/views/layouts/column2.php'.
	 */
	public $layout='//layouts/xml';

	/**
	 * Lists all models.
	 */
	public function actionIndex($id)
	{
		if (isset($id)) {
			$history_entry = History::model()->find('uuid = :uuid', array('uuid' => $id));
			
			$xml = '<?xml version="1.0"?>';
			$xml .= '<utd id="' . $history_entry->uuid . '">';
			$xml .= '<timestamp>' . $history_entry->timestamp . '</timestamp>';
			$xml .= '<header>';
			$xml .= $history_entry->header;
			$xml .= '</header>';
			$xml .= '<body>';
			$xml .= $history_entry->body;
			$xml .= '</body>';
			$xml .= '<footer>';
			$xml .= $history_entry->footer;
			$xml .= '</footer>';
			$xml .= '</utd>';
			
			header("Content-type: application/xml; charset=utf-8");
			header('Content-Disposition: attachment; filename="utd_schema_export_' . $history_entry->uuid . '.xml"');
						
			echo $xml;
		}
	}
}
